//
//  SecViewController.m
//  07_Delegate block
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "SecViewController.h"

@interface SecViewController ()
@property (nonatomic, strong) UITextField *textField;

@end

@implementation SecViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor yellowColor];
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 50, 180, 30)];
    self.textField.backgroundColor = [UIColor redColor];
    // 
    self.textField.text = self.labelTitle;
    [self.view addSubview:self.textField];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    backButton.frame = CGRectMake(50, 100, 100, 30);
    backButton.backgroundColor = [UIColor greenColor];
    [backButton addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backButton];
    
    
}

- (void)click:(UIButton *)button {
//    // 从后向前属性传值 要获取VC
    NSInteger count = self.navigationController.viewControllers.count;
    FirstViewController *first = self.navigationController.viewControllers[count - 2];
    first.textfieldTitle = self.textField.text;
    // 6. 触发协议方法
    if (self.delegate && [self.delegate respondsToSelector:@selector(passValun:)]) {
        [self.delegate passValun:_textField.text];
    }
    [self.delegate passValun:self.textField.text];
    [self.navigationController popToRootViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
